//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using OpenLS.Drawing;
using OpenLS.Drawing.UI;
using OpenLS.Drawing.UI.Internals;

namespace OpenLS.Chart.UI
{
    class PlotAreaFillToBackgroundConverter : IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            FillProperties props = StrictConverter.Convert<FillProperties>(values[0]);
            ColorScheme colorScheme = StrictConverter.Convert<ColorScheme>(values[1]);

            ChartStyle chartStyle = StrictConverter.Convert<ChartStyle>(values[2]);
            if (chartStyle == null)
                chartStyle = new ChartStyle(2);
            return Convert(props, colorScheme, chartStyle);

        }

        static Brush Convert(FillProperties props, ColorScheme colorScheme, ChartStyle chartStyle)
        {
            Contract.Requires(props == null || colorScheme != null);
            if (props == null)
            {
                if (colorScheme == null)
                    return Brushes.Pink;
                ColorBase cb = chartStyle.PlotAreaColor;

                return ColorBaseToBrushConverter.ColorBaseToBrush(cb, colorScheme);
            }
            return FillPropertiesToBrushConverter.FillPropertiesToBrush(props, colorScheme, null);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
